package com.cargohu.aishouyu.member.controller;

import com.cargohu.aishouyu.common.CommonConstants;
import com.cargohu.aishouyu.framework.page.Paging;
import com.cargohu.aishouyu.framework.response.ApiResult;
import com.cargohu.aishouyu.member.dto.ChatPhraseAddDTO;
import com.cargohu.aishouyu.member.dto.ChatPhraseUpdateDTO;
import com.cargohu.aishouyu.member.req.ChatPhraseRequest;
import com.cargohu.aishouyu.member.resp.ChatPhraseDetailVo;
import com.cargohu.aishouyu.member.resp.ChatPhraseResponse;
import com.cargohu.aishouyu.member.service.ChatPhraseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 聊天常用语 控制器
 *
 * @author yww
 * @since 2023-11-28
 */
@Slf4j
@RestController
@RequestMapping(CommonConstants.API_ADMIN_PATH+"/chat-phrase")
@Tag(name = "聊天常用语")
public class ChatPhraseController {

    @Autowired
    private ChatPhraseService chatPhraseService;

    /**
     * 添加聊天常用语
     *
     * @param chatPhraseAddDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/add")
    @Operation(summary = "添加聊天常用语")
    public ApiResult addChatPhrase(@Valid @RequestBody ChatPhraseAddDTO chatPhraseAddDTO) throws Exception {
        boolean flag = chatPhraseService.addChatPhrase(chatPhraseAddDTO);
        return ApiResult.result(flag);
    }

    /**
     * 修改聊天常用语
     *
     * @param chatPhraseUpdateDTO
     * @return
     * @throws Exception
     */
    @PostMapping("/update")
    @Operation(summary = "修改聊天常用语")
    public ApiResult updateChatPhrase(@Valid @RequestBody ChatPhraseUpdateDTO chatPhraseUpdateDTO) throws Exception {
        boolean flag = chatPhraseService.updateChatPhrase(chatPhraseUpdateDTO);
        return ApiResult.result(flag);
    }

    /**
     * 删除聊天常用语
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/delete/{id}")
    @Operation(summary = "删除聊天常用语")
    public ApiResult deleteChatPhrase(@PathVariable Long id) throws Exception {
        boolean flag = chatPhraseService.deleteChatPhrase(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取聊天常用语详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("/get/{id}")
    @Operation(summary = "聊天常用语详情")
    public ApiResult<ChatPhraseDetailVo> getChatPhrase(@PathVariable Long id) throws Exception {
        ChatPhraseDetailVo chatPhraseDetailVo = chatPhraseService.getChatPhraseById(id);
        return ApiResult.success(chatPhraseDetailVo);
    }

    /**
     * 聊天常用语分页列表
     *
     * @param chatPhraseRequest
     * @return
     * @throws Exception
     */
    @PostMapping("/page")
    @Operation(summary = "聊天常用语分页列表")
    public ApiResult<ChatPhraseResponse> getChatPhraseList(@Valid @RequestBody ChatPhraseRequest chatPhraseRequest) throws Exception {
        Paging<ChatPhraseResponse> paging = chatPhraseService.getChatPhraseList(chatPhraseRequest);
        return ApiResult.success(paging);
    }

}
